<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    Array.prototype.myMap = function(callback, useThis){
      let array = this
      let that = useThis

      // for (let i = 0; i < array.length; i++) {
      //   let item = callback.call(that,array[i],i,array)
      //   console.log(item)
      //   res.push(item)
      // }
      // return res

      return array.reduce(function(acc,cur,idx,src){
        acc.push(callback.call(that,cur,idx,src))
        return acc
      },[])
    }
    let arr = [1,2]
    let obj = {a:2}
    let res = arr.myMap(function(item, index, array){
      // return item+1
      return item+this.a
    },obj)
    console.log(res)
  </script>
</body>
</html>